package zheezes.protocol.impl.wt.du;

import java.util.ArrayList;
import java.util.List;

import zheezes.protocol.impl.wt.DataUnit;
import zheezes.protocol.impl.wt.meta.FrzDate;
import zheezes.protocol.impl.wt.meta.WtMtAddr;


public class Ctrl1EDi0242DataUnit extends DataUnit {
	// private WtConAddr addr = new WtConAddr();
	// private byte[] addr = new byte[5];
	private WtMtAddr addr = new WtMtAddr();
	private List<FrzDate> list = new ArrayList<FrzDate>();

	@Override
	public int getData(byte[] buf, int offset) {
		int idx = offset;
		// idx += addr.getBytes(buf, idx);
		// System.arraycopy(addr, 0, buf, idx, addr.length);
		idx += addr.getBytes(buf, idx);
		for (FrzDate f : list) {
			idx += f.getBytes(buf, idx);
		}
		return idx - offset;
	}

	@Override
	public int setData(byte[] buf, int offset, int max) {
		int idx = offset;
		// idx += addr.setBytes(buf, idx, max);
		idx += addr.setBytes(buf, idx, max);
		list.clear();
		while (idx < max) {
			FrzDate f = new FrzDate();
			idx += f.setBytes(buf, idx, max);
			list.add(f);
		}
		return idx - offset;
	}

	@Override
	public int sizeOfData() {
		int size = 0;
		size += addr.size();
		for (FrzDate f : list) {
			size += f.size();
		}
		return size;
	}
}
